def resolveParty(leg, congress, party):
    # Assign independents to the closest party
    # Angus King: Democrat
    if leg == 'K000383':
        return 'Democrat'
    # Joe Lieberman: Democrat
    elif leg == 'L000304':
        return 'Democrat'
    # Bernie Sanders: Democrat
    elif leg == 'S000033':
        return 'Democrat'
    # Dean Barkley gets excluded as a genuine independent (and being shortlived anyhow)
    # Jeffords: Republican before switch in 107th Congress, Democrat after
    elif leg == 'J000072':
        if congress < 107:
            return 'Republican'
        else:
            return 'Democrat'
    # Bob Smith: Republican
    elif leg == 'S000606':
        return 'Republican'
    # James Buckley: Republican
    elif leg == 'B001026':
        return 'Republican'
    # Virgil Goode: Democrat before 107th Congress, Republican thereafter
    elif leg == 'G000280':
        if congress < 106:
            return 'Democrat'
        elif congress > 108:
            return 'Republican'
        else:
            return 'Switcher'
    # Norman Lent: Republican
    elif leg == 'L000243':
        return 'Republican'
    # Now party switchers
    # Arlen Specter: Republican up to 111th Congress, Democrat thereafter
    elif leg == 'S000709':
        if congress < 110:
            return 'Republican'
        elif congress > 112:
            return 'Democrat'
        else:
            return 'Switcher'
    # Ben Campbell: Democrat before 104th Congress, Republican thereafter
    elif leg == 'C000077':
        if congress < 103:
            return 'Democrat'
        elif congress > 105:
            return 'Republican'
        else:
            return 'Switcher'
    # Richard Shelby: Democrat before 104th Congress, Republican thereafter
    elif leg == 'S000320':
        if congress < 103:
            return 'Democrat'
        elif congress > 105:
            return 'Republican'
        else:
            return 'Switcher'            
    # Harry F. Byrd: Democrat
    elif leg == 'B001208':
        return 'Democrat'
    # Parker Griffith: Democrat before 111th Congress, Republican thereafter
    elif leg == 'G000557':
        if congress < 110:
            return 'Democrat'
        elif congress > 112:
            return 'Republican'
        else:
            return 'Switcher'
    # Rodney Alexander: Democrat before 108th Congress, Republican thereafter
    elif leg == 'A000361':
        if congress < 107:
            return 'Democrat'
        elif congress > 109:
            return 'Republican'
        else:
            return 'Switcher'
    # Ralph Hall: Democrat before 108th Congress, Republican thereafter
    elif leg == 'H000067':
        if congress < 107:
            return 'Democrat'
        elif congress > 109:
            return 'Republican'
        else:
            return 'Switcher'
    # Matthew Martinez: We'll leave him as a Democrat given his colorful history
    # Michael Forbes: Republican before 106th Congress, Democrat thereafter
    elif leg == 'F000257':
        if congress < 105:
            return 'Democrat'
        elif congress > 107:
            return 'Republican'
        else:
            return 'Switcher'
    # Jimmy Hayes: Democrat before 104th Congress, Republican thereafter
    elif leg == 'H000390':
        if congress < 103:
            return 'Democrat'
        elif congress > 105:
            return 'Republican'
        else:
            return 'Switcher'
    # Michael Parker: Democrat before 104th Congress, Republican thereafter
    elif leg == 'P000066':
        if congress < 103:
            return 'Democrat'
        elif congress > 105:
            return 'Republican'
        else:
            return 'Switcher'
    # Billy Tauzin: Democrat before 104th Congress, Republican thereafter
    elif leg == 'T000058':
        if congress < 103:
            return 'Democrat'
        elif congress > 105:
            return 'Republican'
        else:
            return 'Switcher'
    # Greg Laughlin: Democrat before 104th Congress, Republican thereafter
    elif leg == 'L000119':
        if congress < 103:
            return 'Democrat'
        elif congress > 105:
            return 'Republican'
        else:
            return 'Switcher'
    # Nathan Deal: Democrat before 104th Congress, Republican thereafter
    elif leg == 'D000168':
        if congress < 103:
            return 'Democrat'
        elif congress > 105:
            return 'Republican'
        else:
            return 'Switcher'
    # Tommy F. Robinson: Democrat before 101st Congress, Republican thereafter
    elif leg == 'R000354':
        if congress < 100:
            return 'Democrat'
        elif congress > 102:
            return 'Republican'
        else:
            return 'Switcher'
    # James W. Grant: Democrat before 101st Congress, Republican thereafter
    elif leg == 'G000382':
        if congress < 100:
            return 'Democrat'
        elif congress > 102:
            return 'Republican'
        else:
            return 'Switcher'
    # Phil Gramm: Democrat before 98th Congress, Republican thereafter
    elif leg == 'G000365':
        if congress < 97:
            return 'Democrat'
        elif congress > 99:
            return 'Republican' 
        else:
            return 'Switcher'
    # Andy Ireland: Democrat before 98th Congress, Republican thereafter
    elif leg == 'I000029':
        if congress < 97:
            return 'Democrat'
        elif congress > 99:
            return 'Republican'
        else:
            return 'Switcher'
    # Bob Stump: Democrat before 97th Congress, Republican thereafter
    elif leg == 'S001044':
        if congress < 96:
            return 'Democrat'
        elif congress > 98:
            return 'Republican'
        else:
            return 'Switcher'
    # Eugene Atkinson: Democrat before 97th Congress, Republican thereafter
    elif leg == 'A000329':
        if congress < 96:
            return 'Democrat'
        elif congress > 98:
            return 'Republican'
        else:
            return 'Switcher'
    # John Jarman: Democrat before 94th Congress, Republican thereafter
    elif leg == 'J000057':
        if congress < 93:
            return 'Democrat'
        elif congress > 95:
            return 'Republican'
        else:
            return 'Switcher'
    else:
        return party[leg]